/**
 * Copyright &copy; Sunit Katkar (sunitkatkar@gmail.com) http://sunitkatkar.blogspot.com
 */
package com.barunsw.bwf.ems.common.controller;

import java.security.Principal;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.barunsw.bwf.ems.util.TimeUtil;

/**
 * {@link WebSocketsMVCController} is for handling the user login and
 * logout. Simple form based security is used. Refer to
 * <code>application-security.xml</code> and <code>web.xml</code> for details.
 * 
 * @author <a href="mailto:sunitkatkar@gmail.com">Sunit Katkar</a>
 * @since 1.0
 * @version 1.0.0.1
 */
@Controller
public class WebSocketsMVCController {
    private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketsMVCController.class);
    
    /**
     * Method gets executed when there are requests to the
     * <code>/secured/basicWebsockets</code> url. This url is called after a
     * successful login.
     * 
     * @param model
     * @param principal
     * @param locale
     * @return
     */
    @RequestMapping("/sample/alarmview")
    public String alarmViewPage(Model model, Principal principal, Locale locale) {
        // Get a simple human readable date and time
        String formattedDate = TimeUtil.getSimpleDate(locale);

        // Get the logged in user's name
        String userName = principal.getName();

        // Set some sample messages to show on the landing 'basicWebsockets.jsp'
        // page.
        
        model.addAttribute("username", userName);
        model.addAttribute("time", formattedDate);

        LOGGER.info(
                "Request from user:{} for /sample/alarmview url processed at time:{}",
                userName, formattedDate);
                //userName, formattedDate);

        return "sample/alarmview";
    }
}